/**
 * @param {number[][]} bookings
 * @param {number} n
 * @return {number[]}
 */
var corpFlightBookings = function (bookings, n) {
  let diff = Array(n).fill(0)
  bookings.forEach(book => {
    //差分数组  https://cloud.tencent.com/developer/article/1629357
    let [i, j, v] = book
    diff[i - 1] += v
    if (j < n && i !== n) {
      diff[j] -= v
    }
  })
  for (let i = 1; i < diff.length; i++) {
    diff[i] = diff[i - 1] + diff[i]
  }
  return diff
}
let bookings = [
  [1, 2, 10],
  [2, 3, 20],
  [2, 5, 25]
]
let n = 5
bookings = [
  [1, 2, 10],
  [2, 2, 15]
]
n = 2
bookings = [
  [3, 3, 5],
  [1, 3, 20],
  [1, 2, 15]
]
n = 3
bookings = [
  [2, 2, 30],
  [3, 3, 25],
  [3, 3, 20]
]
n = 3
console.log(corpFlightBookings(bookings, n))
